package model;

import java.util.Iterator;
import java.util.Vector;

/**
 * The Observee class allows {@link Observer}s to register, deregister and be notified by this
 * class.
 *
 */
public abstract class Observee {
	public Vector<Observer> observerList;
	
	/**
	 * Constructor of Observee
	 */
	public Observee() {
		this.observerList = new Vector<Observer>();
	}
	
	/**
	 * Notifies all registered observers with the provided WindowEvent.
	 * @param event is the Event
	 */
	public void notifyObservers(final WindowEvent event) {
		final Iterator<Observer> i = this.observerList.iterator();
		if (i.hasNext()){
			final Observer current = i.next();
			current.update(event);
		}
	}
	
	/**
	 * Registers the provided Observer at this Observee.
	 * @param observer is the Observer.
	 */
	public void register(final Observer observer){
		if (!this.observerList.contains(observer))
			 this.observerList.add(observer);
	}
	
	/**
	 * Deregisters the provided Observer at this Observee.
	 * @param observer is the Observer.
	 */
	public void deregister(final Observer observer){
		if (this.observerList.contains(observer))
			this.observerList.remove(observer);
	}
}
